package toolsUseCourse.Script;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class FillFormProjectLibrary {
//    填写网页表单的脚本
    public static void main(String[] args) throws AWTException{
//        input_data();
        input_data_test();
//        test


    }
    public static void input_data() throws AWTException{
        Robot robot = new Robot();
        robot.delay(5000);
//        审计项目名称
        String text1 = "审计项目名称test";
        key_event_paste(text1);
        key_event_table();
//        编号：默认
        key_event_table();
//        审计单位名称test
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(100);
//        被审计单位名称
        key_event_table();
        String text2 = "1000 顶级机构";
        key_event_paste(text2);
//        审计期间
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(100);
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(100);
//        来文标题
        key_event_table();
        String text3 = "来文标题test";
        key_event_paste(text3);
//        来文日期
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(100);
//        项目年度,默认

//        审计文号
        key_event_table();
        String text4 = "审计文号test";
        key_event_paste(text4);
//        审计层级
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        审计类型
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        审计方式
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        是否需要整改计划
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        整改计划上报时间
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        整改结果上报时间
        key_event_table();
        robot.keyPress(KeyEvent.VK_KP_DOWN);
        robot.keyRelease(KeyEvent.VK_KP_DOWN);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
//        拓展字段1-5
        int i=5;
        while (i!=0){
            key_event_table();
            i--;
        }
//        备注
        key_event_table();
        String text5 = "备注test";
        key_event_paste(text5);
    }
    public static void input_data_test() throws AWTException{
        Robot robot = new Robot();
        robot.delay(5000);
//        审计项目名称
        String text1 = "审计项目名称test";
        key_event_paste(text1);
//        编号：默认
        key_event_table();
//        审计单位名称test
        key_event_table();
        key_event_down();
        robot.delay(100);
        key_event_down();
        robot.delay(100);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(100);
//        被审计单位名称
        key_event_table();
        String text2 = "1000 顶级机构";
        key_event_paste(text2);
        robot.delay(600);
//        审 1000 顶级机构   计期间
        key_event_table();
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
        key_event_table();
        robot.delay(600);
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        来文标题
        key_event_table();
        String text3 = "来文标题test";
        key_event_paste(text3);
        robot.delay(600);

//        来文日期
        key_event_table();
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);

//        项目年度,默认
        key_event_table();
//        审计文号
        key_event_table();
        robot.delay(600);
        String text4 = "审计文号test";
        key_event_paste(text4);
        robot.delay(600);
//        审计层级
        key_event_table();
        robot.delay(600);
        key_event_down();
        robot.delay(600);
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        审计类型
        key_event_table();
        key_event_down();
        robot.delay(600);
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        审计方式
        key_event_table();
        key_event_down();
        robot.delay(600);
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        是否需要整改计划
        key_event_table();
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        整改计划上报时间
        key_event_table();
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        整改结果上报时间
        key_event_table();
        key_event_down();
        robot.delay(600);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(600);
//        拓展字段1-5
        int i=5;
        while (i!=0){
            key_event_table();
            i--;
        }
//        备注
        key_event_table();
        robot.delay(600);
        String text5 = "备注test";
        key_event_paste(text5);
        robot.delay(600);
    }

    public static void key_event_down() throws AWTException{
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_DOWN);
        robot.keyRelease(KeyEvent.VK_DOWN);
    }
    public static void key_event_table() throws AWTException{
//        tab键切换到下一个文本框
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_TAB);
        robot.keyRelease(KeyEvent.VK_TAB);
        robot.delay(10);
    }

    public static void key_event_paste(String input_text) throws AWTException{
//        在文本框输入input_text
        String text = input_text;
        StringSelection stringSelection = new StringSelection(text);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, stringSelection);
        
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
    }


}
